<?php
// Start session
session_start();

// If customer is logged in theset the customer id
$customer_id = $_SESSION['userid'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<link rel="SHORTCUT ICON" href="images/url_logo.png">

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="description" content="Buy secondhand horse saddles online with our large range of horse saddles for most disciplines including General Purpose | Dressage | Eventing | Working | Hunter and VSD. Buy or sell used horse saddles online.">

	<title>24-7 Saddles | Used horse saddles =& second hand horse saddles</title>

	<link href="css/header.css" rel="stylesheet" type="text/css">
	<link href="css/navigation.css" rel="stylesheet" type="text/css" />
	<link href="css/products.css" rel="stylesheet" type="text/css" />
	<link href="css/paginate.css" rel="stylesheet" type="text/css" />
	<link href="css/products_product.css" rel="stylesheet" type="text/css" />

	<style type="text/css">
	body 
	{
		background-image: url(images/wood2.jpg);
		background-repeat: repeat-x;
		margin: 0px;
		background-position: left top;
		background-attachment: fixed;
		background-color: #000000;
		padding-top: 0px;
		padding-right: 0px;
		padding-bottom: 0px;
		padding-left: 0px;
	}
	</style>

</head>

<body>

<div id="page_container">

		<?php 
		
		include "header.php";
		include "navigation.php" 
		
		?>

  <div id="saddle_information_container">

		<h1>Second hand horse saddles & used horse saddles online</h1>
		<h2>Free tial purchase available on all second hand horse saddles</h2>

		<p class="section1">Below you can find our range of quality second hand, used horse saddles. All of our saddles are available for delivery throughout UK or for collection from Croft, Warrington. 24-7 Saddles offer saddles from a variety of manufacturers. </p>

		<p class="section2">We offer a range of different sizes and styles to fit a variety of horse types. We also provide a trial service on purchase of all of our saddles, just to make sure the saddle you’re purchasing is right for your horse. </p>

		<p class="section3">Our used General purpose saddles are a multi-purpose saddle range which can accommodate every requirement to achieve the best saddle for rider, horse and discipline.</p>

	</div> <!-- saddle_information_container -->

		<img id="saddle_makes" src="images/saddle_makes.png" width="980" height="60" />

	<div id="product_details_container">

		<?php
		
		//////////
		//Paginate
		//////////
		
		include('connect.php');	
	
		$tableName="saddles";		
		$targetpage = "second_hand_all_saddles.php"; 	
		$limit = 6; 
	
		$query = "SELECT COUNT(*) as num FROM $tableName WHERE product_status != 'Sold' AND product_sub_catagory = 'general_purpose'";
		$total_pages = mysql_fetch_array(mysql_query($query));
		$total_pages = $total_pages[num];
	
		$stages = 3;
		$page = mysql_escape_string($_GET['page']);
		
		if($page)
		{
			
			$start = ($page - 1) * $limit; 
		
		}
		else
		{
			
			$start = 0;	
			
		}	
	
    	// Get page data
		$query1 = "SELECT * FROM $tableName WHERE product_status != 'Sold' AND product_sub_catagory = 'general_purpose' LIMIT $start, $limit";
		$result = mysql_query($query1);
	
		// Initial page num setup
		if ($page == 0)
		{
			$page = 1;
		}
		
		$prev = $page - 1;	
		$next = $page + 1;							
		$lastpage = ceil($total_pages/$limit);		
		$LastPagem1 = $lastpage - 1;					
	
	
		$paginate = '';
		if($lastpage > 1)
		{	
		
			$paginate .= "<div class='paginate'>";
			// Previous
		
			if ($page > 1)
			{
				$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
			}
			else
			{
			
				$paginate.= "<span class='disabled'>previous</span>";	
			}
					
		// Pages	
		if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
				{
					$paginate.= "<span class='current'>$counter</span>";
				}
				else
				{
					$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
				}
			}
			elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
			{
				// Beginning only hide later pages
				if($page < 1 + ($stages * 2))		
				{
					for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
				{
					if ($counter == $page)
					{
						$paginate.= "<span class='current'>$counter</span>";
					}
					else
					{
						$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
					}
					$paginate.= "...";
					$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
					$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
					}
				
				// Middle hide some front and some back
				elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
				{
					$paginate.= "<a href='$targetpage?page=1'>1</a>";
					$paginate.= "<a href='$targetpage?page=2'>2</a>";
					$paginate.= "...";
					for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
					{
						if ($counter == $page)
						{
							$paginate.= "<span class='current'>$counter</span>";
						}
						else
						{
							$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";
						}					
					}
						$paginate.= "...";
						$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
						$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
				}
				// End only hide early pages
				else
				{
					$paginate.= "<a href='$targetpage?page=1'>1</a>";
					$paginate.= "<a href='$targetpage?page=2'>2</a>";
					$paginate.= "...";
					for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
					{
						if ($counter == $page)
						{
							$paginate.= "<span class='current'>$counter</span>";
						}
						else
						{
							$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";
						}					
					}
				}
			}
					
			// Next
			if ($page < $counter - 1)
			{ 
				$paginate.= "<a href='$targetpage?page=$next'>next</a>";
			}
			else
			{
				$paginate.= "<span class='disabled'>next</span>";
			}
			
			$paginate.= "</div>";		
		}
		
			/////////////////////////////////
			//Display paginate at top of page
			/////////////////////////////////
 		
			if ($total_pages > 6)
			
			{
			
				echo "<div id='paginate_container'>";
 		
			    echo $paginate;
				
				echo '</div>';
			
			}
 		
			/////
			//End
			/////
		
		/////
		//End
		/////
 
?>

<?php 
		//////////////////
		//Display priducts
		//////////////////
		
		echo "<div id='new_products_container'>";
	
		echo "<ul>";

		while($row = mysql_fetch_array($result)) //Get product details using query from paginate
	 
	 	{
				 
			$product_name = $row['product_name'];
			$product_status = $row['product_status'];	
			$product_cost = $row['product_cost']; 
			$product_description = $row['product_description'];
			$product_id = $row['product_id'];
			$product_row_id = $row['id'];
			$product_offer = $row['product_offer'];
			$product_link = preg_replace('/\s+/', '_', $product_name);
	
			echo '
			<li>
				<form action="product_details.php?'.$product_name.'_second_hand_horse_saddles" method="post" name="product">
					<img alt="24-7saddles second hand horse saddle '.$product_name.'" id="product_imgage_large" src="images/saddles/'.				  					$product_row_id.'_1.jpg" width="500" height="500" />
					<a href="saddles/'.$product_link.'.php" class="product_button">More details</a>
					<h4>'.$product_name.'</h4>';
			
			/////////////////
			//Product banner
			/////////////////
			
			//On trial banner
			
			if($product_status == "On-trial") //if saddle is on trial
			{
				echo '<p id="ontrial_banner">On-trial</p>';
			}
	
			if($product_status != "On-trial") //if saddle isnt on trial
			{
			
				//Product offer banner
				
				if($product_offer != "") //if saddle has is on offer
				{
				echo '<p id="product_banner">'.$product_offer.'</p>';
				}
		
				if($product_offer == "") //if saddle isnt on offer
				{
					
					//No banner
				
					echo '';
				}
			}
			
			/////
			//End
			/////
	
					echo '
					<p id="product_price"><i>Only</i> £'.$product_cost.'</p>
					<p id="product_description">'.$product_description.'</p>';
		
					//echo '<input name="product_row_id" type="hidden" value="'.$product_row_id.'" />';
					//echo '<input name="view_product" type="submit" class="product_button" value="More details" />';
	
				echo '
				</form>			
			
				<p id="product_id"><i>Product ID: '.$product_id.'</i></p>
				<li>';
	
				}
	 
				echo "</ul>";
	 
				echo "</div>";
	
 			/////////////////////////////////
			//Display paginate at bottom of page
			/////////////////////////////////
			
			if ($total_pages > 6)
			
			{
			
				echo "<div id='paginate_container'>";
 		
			    echo $paginate;
				
				echo '</div>';
			
			}
			 		
			/////
			//End
			/////
		
		/////
		//End
		/////
		
?>

</div> <!--product_details_container-->

</div> <!--page_container-->

<?php 

include "footer.php" 

?>

</body>

</html>